class WinstreakPublisher < Facebooker::Rails::Publisher

  helper TeamsHelper,BetsHelper,MatchesHelper,ApplicationHelper

  def self.default_url_options
    {:host=>"apps.railser.com"}
  end

  def update_profile(user)
    send_as :profile
    recipients user.facebook_user
    profile_main render(:partial=>"profile_main" ,:locals=>{:user=>user})
    profile render(:partial=>"profile" ,:locals=>{:user=>user})
  end

  def winstreak_remain(user)
    delayed true

    send_as :user_action
    from user.facebook_user
    data :winstreak_remain=>user.winstreak.streak_remain,:prize=>user.prize.name
  end

  def winstreak_goal(user)
    delayed true

    send_as :user_action
    from user.facebook_user
    data :prize=>user.prize.name,:user=>user
  end

  def winstreak_new_record(user)

    match = user.matches.next

    delayed true

    send_as :user_action
    from user.facebook_user
    data :prize=>user.prize.name,
      :team1=>match.home_team.name,
      :team2=>match.away_team.name,
      :handlicap=>match.point_spread,
      :win_remain=>user.winstreak.streak_remain,
      :winstreak=>user.winstreak.streak_count
  end

  protected
    def winstreak_remain_template
      one_line_story_template "{*actor*} is {*winstreak_remain*} wins away from a free {*prize*}.<a href='#{app_url}'>Click here to win one as well</a>"
    end

    def winstreak_goal_template
      one_line_story_template "{*actor*} <a href='#{app_url}'>WON a FREE {*prize*}</a>.Congratulate {*actor*}!!!"
    end

    def winstreak_new_record_template
      one_line_story_template "{*actor*} needs {*team1*} to beat {*team2*} on a {*handlicap*} handicap to beat his {*winstreak*} wins best streak. {*actor*} is {*win_remain*} more wins from a free {*prize*}.<a href='#{app_url}'> Click here to win one as well</a>" 
    end

end
